<?php
Yii::import('ext.epmenu.*');

class EPMenu extends CWidget{

	private $_root;
	private $_renderer;
	private $_parser;
	public $rendererClass='EPMenuListRenderer';
	public $rendererParams=array();
	public $parserClass='EPMenuArrayParser';
	public $parserParams=array();
	public $data;
	public $htmlOptions=array('class'=>'epmenu_mainmenu');
	public $menuId;
	

	public function init(){


		if(!class_exists($this->parserClass,false)){
			Yii::import('ext.epmenu.parser.'.$this->parserClass);
		}
		$this->_parser=new $this->parserClass;
		if(!empty($this->parserParams)){
			$this->_parser->init($this->parserParams);
		}

		if(!class_exists($this->rendererClass,false)){
			Yii::import('ext.epmenu.renderer.'.$this->rendererClass);
		}
		$this->_renderer=new $this->rendererClass;
		if(!empty($this->rendererParams)){
			$this->_renderer->init($this->rendererParams);
		}
	}

	public function run(){
		if(empty($this->_root)){
			$this->_root=$this->_parser->parse($this->data);
		}
		$htmlOptions=$this->htmlOptions;
		if(!empty($this->menuId)){
			$htmlOptions['id']=$this->menuId;
		}
		echo $this->_renderer->render($this->_root,$this->htmlOptions);
	}
	
	


}

